package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Classname PortAgreementAttrHandler
 * @Description 接入电路类型=数字电路 且 接口类型（CE端信息）=G.703 或 V.35，端口封装协议=显示+必填，默认值 HDLC
 * @Author zhang.song
 * @Date 2021-03-10 20:50
 */
public class PortAgreementAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

//    @Override
//    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
//        if(KiteStringUtils.equals(attr.getFieldName(),"2_0000054")){
//            String serviceOfferId = data.getServiceOfferId();
//            IOperateSceneInstService operateSceneInstService = SpringUtil.getBean(IOperateSceneInstService.class);
//            //追单环节不可编辑
//            if(LocalServiceOfferConsts.SERVICE_OFFER_FOLLOW.equals(serviceOfferId)){
//                attr.setIsEdit(KeyConsts.IFTRUE_F);
//            }
//            operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr);
//        }
//    }

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        //联动缺失 AcceCircuitTypeAttrHandler逻辑移过来
        if(KiteStringUtils.equals(attr.getFieldName(),"2_0000053")){
            //河南个性化 【接入电路类型】(关键属性，CE端信息)选择项包含汇聚层（100006964）、OLT（100006949）、IPRAN（1_0000203）,非河南去掉，默认包含
            String provinceCode = ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr();
            if(!LocalKeyConsts.PROVINCE_HENAN.equals(provinceCode)){
                attr.getAttrValues().removeIf(targetAttr -> KiteStringUtils.equals(targetAttr.getAttrValue(), "100006964"));
                attr.getAttrValues().removeIf(targetAttr -> KiteStringUtils.equals(targetAttr.getAttrValue(), "100006949"));
                attr.getAttrValues().removeIf(targetAttr -> KiteStringUtils.equals(targetAttr.getAttrValue(), "1_0000203"));
            }
        }
        super.after(attr, inst, data);
    }
}
